package cn.zhyjohn.paysystem.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

/**
 * 统一返回
 * 
 * @Description
 * @author JOHN
 * @version 1.0
 * 
 */
@Data
public class Response {

	private static final String OK = "OK";

	private static final String ERROR = "ERROR";

	public static final Integer SUCCESS_CODE = 200;

	public static final Integer ERROR_CODE = 500;

	private boolean success;

	private int code;

	private String message;
	
	private Object data;
	
	@JsonInclude(JsonInclude.Include.NON_NULL)//null时不输出
	private Long total;

	/**
	 * 成功提示
	 * 
	 * @return Response
	 *
	 */
	public Response success() {
		this.success = true;
		this.code = SUCCESS_CODE;
		this.message = OK;
		return this;
	}

	/**
	 * 成功提示
	 * 
	 * @param message
	 *            提示消息
	 * @return Response
	 *
	 */
	public Response success(String message) {
		this.success = true;
		this.code = SUCCESS_CODE;
		this.message = message;
		return this;
	}

	/**
	 * 数据
	 * 
	 * @param data
	 *            数据
	 * @return Response
	 *
	 */
	public Response data(Object data) {
		this.success = true;
		this.code = SUCCESS_CODE;
		this.message = OK;
		this.data = data;
		return this;
	}

	/**
	 * 数据
	 * @param data
	 * 			数据
	 * @param total
	 * 			条数
	 * @return
	 */
	public Response data(Object data, long total) {
		this.success = true;
		this.code = SUCCESS_CODE;
		this.message = OK;
		this.data = data;
		this.total = total;
		return this;
	}

	/**
	 * 失败提示
	 * 
	 * @return Response
	 *
	 */
	public Response failure() {
		this.success = false;
		this.code = ERROR_CODE;
		this.message = ERROR;
		return this;
	}

	/**
	 * 失败提示
	 * 
	 * @return Response
	 *
	 */
	public Response failure(String message) {
		this.success = false;
		this.code = ERROR_CODE;
		this.message = message;
		return this;
	}

	/**
	 * 失败提示
	 * 
	 * @param message
	 *            提示消息
	 * @param code
	 *            错误代码
	 * @return Response
	 *
	 */
	public Response failure(String message, int code) {
		this.success = false;
		this.code = code;
		this.message = message;
		return this;
	}

}